﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Skynet.LiteFoundation.BusinessEntities;
using System.Data;

namespace Skynet.LiteAdministration.Views.MaintenanceExamCategories
{
    public  class MaintenanceExamCategoryPresenter : Infrastructure.WpfClient.Views.Master.MasterPresenter<IMaintenanceCategoriesView>
    {

        public MaintenanceExamCategoryPresenter(IUnityContainer container)
            : base(container)
        {
 
        }

        [Dependency]
        public Skynet.LiteFoundation.DataAccess.IExamCategoryRepository ExamCatRep { get; set; }


        [Dependency]
        public SkyNetLibraryEntities Context { get; set; }

        public ExamCategory CurrentCategory { get; set;  }
        public override void OnViewReady()
        {
            Load();
        }
        public void Load()
        {

            var id =  Guid.Parse("02BE3564-35A3-454D-BE3C-D990FB0D9035");

            var query = from c in this.Context.ExamCategories
                        where c.Id == id
                        select c;
            this.CurrentCategory = query.FirstOrDefault();
            this.InvokePropertyChanged("CurrentCategory"); 
        }

        public void Add(ExamCategory exam)
        {
           // this.ExamCatRep.Maintenance(exam); 
            Context.ExamCategories.AddObject(exam);
            Context.SaveChanges();
        }


        internal void Save()
        {
            try
            {
                this.Context.SaveChanges(); 
            }
            catch (OptimisticConcurrencyException ex)
            {
                System.Windows.MessageBox.Show(ex.Message);                              
            }
            
        }
    }
}
